home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: MegaDisc / MegaDisc 38 (1994-02)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip / MegaDisc 38 (1994-02)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf / Tutes_&_CLI / PowerScripting / PowerScripting
Text File  |  1994-02-14  |  9KB  |  221 lines

  1.  
  2.                            POWER SCRIPTING
  3.  
  4.  
  5.                           by Paul McLachlan
  6.  
  7.  
  8.  
  9.   38 *^* 38 *^* 38 *^* 38 *^* 38 *^* 38 *^* 38 *^* 38 *^* 38 *^* 38
  10.  
  11.  
  12.     The script file is one of those wonderful sections of the Amiga
  13.   that is both easy to use and wonderfully complicated.  (Huh?) You
  14.   see, most users will be familiar with the most common script file -
  15.   the startup-sequence.  This is also the easiest form of a script
  16.   file, a sequence of commands to be executed.  There are many
  17.   advanced features that are available through scripts files, that not
  18.   only enable you to do wierd and wonderful things, but can be life
  19.   savers.
  20.     
  21.     
  22.     FORMATTING
  23.     
  24.     Now, I've seen around, that some people have come up with the idea
  25.   of using a script to format disks.  Your average format command:
  26.     
  27.         Format drive df0: name "Empty" NOICONS QUICK
  28.         
  29.   is quite bothersome to type in quickly.  So putting this line in a
  30.   file called 'fmt0' or similar in S:  and 'protect'ing it (+s) will
  31.   enable you ×to simply type:
  32.     
  33.         fmt0
  34.     
  35.   to quickly format the disk in df0:.  All very wonderful.  Now say
  36.   you have 3 disk drives.  You put three of the scripts in with
  37.   slightly different names and functions, right?
  38.  
  39.     Not at all.  Script files allow you to enter arguments.  That is,
  40.   you could (and will, by the end of this), enter, to format DF1:
  41.     
  42.         fmt df1:
  43.     
  44.     Now, that is a script file you're calling, and not a CLI command
  45.   that someone wrote.  Lets take a look at it:
  46.     
  47.         ;   Fmt <drive>
  48.         ;       Script to format the disk in the supplied drive
  49.         
  50.         .bra {
  51.         .ket }
  52.         
  53.         .key input
  54.         
  55.         FORMAT drive {input} name "Empty" NOICONS QUICK
  56.         
  57.     Interesting, huh?  Lets have a little look at what some of these
  58.   lines do.  Firstly, there are two lines of comments, to tell you at
  59.   a later date what this script does, and then there are another two
  60.   lines, which I have grouped together.
  61.  
  62.     These two command .bra & .ket are quite important.  They enable
  63.   you to choose which brackets to use for your variables.  I have
  64.   chosen braces '{}'.
  65.  
  66.     The next line looks good.  'input' is the name of the variable
  67.   that you want to enter.  The .key command is effectively declaring
  68.   it.
  69.  
  70.     The final line is the format command, with the drive replaced by
  71.   {input}, which effectively says the contents of the variable input,
  72.   or, what the user put after Fmt in the command line.  This all adds
  73.   up to the ability to:
  74.     
  75.         Fmt df0:
  76.         
  77.     or
  78.     
  79.         Fmt df1:
  80.     
  81.     With one script command and some power scripting.  A slight
  82.   difference to this example is the 'Wipe' command.  It is pretty
  83.   similar, but shows a slight difference which may point out something
  84.   you didn't realise:
  85.     
  86.         .bra {
  87.         .ket }
  88.         .key device
  89.         
  90.         echo "WIPE {device}*NPress RETURN to continue, CNTRL-C to stop"
  91.         FORMAT >NIL: drive {device} name "Erased" NOICONS QUICK
  92.         
  93.     Check the echo command.  It actually warns you (just like the
  94.   format command would have) of which drive you are about to kill.
  95.     
  96.     
  97.     FILE CREATION
  98.     
  99.     One of the commands I miss from my old Apple II (shame, Apple II,
  100.   shame), is the ProDOS Create command.  This command 'created' an
  101.   empty file.  Why is this useful?  Well, I use it for various things
  102.   but mainly in testing programs and so forth.  Nevertheless, it shows
  103.   an interesting aspect of the echo command.
  104.  
  105.     Lets take a look at my S:Create file:
  106.     
  107.         .bra {
  108.         .ket }
  109.         .key file
  110.         
  111.         echo >{file} "" NOLINE
  112.     
  113.     Now, the redirection of the echo command to a file is just an
  114.   application of output redirection.  Output Redirection simply means
  115.   that any output that the program would generally produce is put in a
  116.   file, instead.  The only type of output redirection is append, where
  117.   you:
  118.     
  119.         echo >>myfile "*N"
  120.     
  121.   and this appends a return to the end of the file, while:
  122.     
  123.         echo >myfile "*N"
  124.     
  125.   would erase the file and make a new one that has just a return in
  126.   it.
  127.     
  128.     I used to use the append output redirection as a type of log.  In
  129.   my startup sequence I would have a command sequence:
  130.     
  131.         echo >>S:Logfile "*NStartup executed " NOLINE
  132.         date >>S:Logfile
  133.     
  134.   and this would write startup executed and the date everytime to a
  135.   logfile that gradually got larger and larger until I deleted it.
  136.     
  137.     USING THE LIST COMMAND
  138.     
  139.     This command is a powerful script command, although it sometimes
  140.   takes a while for people to realise it.  It is the list 'LFORMAT'
  141.   option that makes the list command so powerful.
  142.  
  143.     My example for this command comes from the days when I ran a BBS.
  144.   Whenever a batch of new Fish disks came in, I had to archive the
  145.   whole lot and copy it onto the harddrive.  This, quite naturally,
  146.   became a tedious procedure.  To start with, lets take a look at the
  147.   format of a standard fish disk.  Say, #601:
  148.     
  149.                PP (dir)
  150.                     Docs (dir)
  151.                       Copyright.DOC                    Copyright.DOC.info
  152.                       PP.DOC                           PP.DOC.info
  153.                       PP.history                       PP.history.info
  154.                       Shareware.ANGER!                 Shareware.ANGER!.info
  155.                  Docs.info                        PP
  156.                  PP.info                          ReadMe.fnf
  157.                  Source.lzh                       
  158.                APipe (dir)
  159.                  APipe-Handler                    APipe-Handler_rev.h
  160.                  APipe-Handler_rev.i              APipe-Handler_rev.rev
  161.                  child.asm                        Makefile
  162.                  Mountlist                        pgmpipe.c
  163.                  README                           README.fnf
  164.                  README.info                      POSTER
  165.                c (dir)
  166.                  MuchMore                         XIcon
  167.                Intuisup (dir)
  168.                     Texts (dir)
  169.                       .info                            source.lzh
  170.                       texts_test                       texts_test.info
  171.                  Borders.info                     Editor.info
  172.                  Files.info                       Gadgets.info
  173.                  InstallLibrary                   InstallLibrary.info
  174.                  Language.info                    Library.info
  175.                  Menus.info                       Pointer.info
  176.                  ReadMe                           ReadMe.fnf
  177.                  ReadMe.info                      Render.info
  178.                  Requester.info                   Texts.info
  179.             APipe.info                       Catalog
  180.             Catalog.info                     Contents
  181.             Contents.info                    Disk.info
  182.             Distribution                     Distribution.info
  183.             Intuisup.info                    Orders
  184.             Orders.info                      PP.info
  185.             ReadMeFirst                      ReadMeFirst.info
  186.             Submissions                      Submissions.info
  187.  
  188.     
  189.     Now, this is a pretty standard directory listing, and all fish
  190.   disks follow the same format.  I had to devise a script file that
  191.   would create archives called PP.lha, APipe.lha and Intuisup.lha, and
  192.   put into them the contents of those directories.  Another couple of
  193.   things to be noted:  Sometimes directories contain a readme.fnf file
  194.   or a POSTER.  These files are unnecessary for the BBS, and so I am
  195.   not going to archive them.
  196.  
  197.     Take a look at this script file:
  198.     
  199.       ;  This batch file archives all the directories on the internal
  200.       ;  disk into separate archives for each - to the current directory.
  201.  
  202.       list >RAM:a.script df0:~C dirs LFORMAT="LHA -r -x a %N.LHA %P%N/#?"
  203.  
  204.       echo "Archiving Files....  Please wait"
  205.       execute ram:a.script
  206.       echo "All DONE!"
  207.  
  208.     
  209.     Now, isn't that clever.  (You may need to consult your AmigaDOS
  210.   manual for the uses of all the %P's and so on in the LFORMAT string)
  211.  
  212.  
  213.     Finally, to finish off the tutorial, on your workbench disk, load
  214.   up the S:SPat script file.  This adds pattern matching to commands
  215.   that do not normally support it.  It uses most of the techniques I
  216.   have described above.
  217.  
  218.  
  219.   38 *^* 38 *^* 38 *^* 38 *^* 38 *^* 38 *^* 38 *^* 38 *^* 38 *^* 38
  220.  
  221.